<template>
    <div class="app-container">
        <el-form ref="form" :model="form" :rules="rules">
            <el-form-item label="项目名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入项目名称"/>
            </el-form-item>
            <el-form-item label="项目单位" prop="projectUnit">
                <el-input v-model="form.projectUnit" placeholder="请输入项目单位"/>
            </el-form-item>
            <el-form-item label="项目地址" prop="address">
                <el-input v-model="form.address" placeholder="请输入项目地址"/>
            </el-form-item>

            <el-form-item label="用户首页" prop="defaultIndex">
                <el-select v-model="form.defaultIndex"
                           placeholder="用户首页"
                >
                    <el-option
                        v-for="(item, index) in indexList"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>

            <el-form-item label="通知方式">
                <el-checkbox-group v-model="form.noticeMode">
                    <el-checkbox label="0">短信</el-checkbox>
                    <el-checkbox label="1">邮件</el-checkbox>
                </el-checkbox-group>
            </el-form-item>

            <!--        <el-form-item label="实图主页背景图">-->
            <!--          <image-upload v-model="form.homepageImage" />-->
            <!--        </el-form-item>-->

            <!--        <el-form-item label="气象站背景图">-->
            <!--          <image-upload v-model="form.weatherImage" />-->
            <!--        </el-form-item>-->

            <el-form-item label="控制点分组权限" prop="loopGroupAuth">
                    <el-radio-group v-model="form.loopGroupAuth">
                        <el-radio :label="true">开启</el-radio>
                        <el-radio :label="false">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm">保 存</el-button>
            </el-form-item>
        </el-form>


    </div>
</template>

<script>
import { getProjectInfo, updateProject } from '@/api/business/project'
import { listSelectUser } from '@/api/business/showIndex'

export default {
    name: 'index',
    data() {
        return {
            form: {
                noticeMode:["0"]
            },
            // 表单校验
            rules: {},
            indexList: []
        }
    },
    created() {
        this.init()
        this.getIndexList()
    },
    methods: {
        init() {
            getProjectInfo().then(response => {
                this.form = response.data
                if(this.form.noticeMode===null){
                    this.form.noticeMode=[]
                }
            })
        },
        submitForm() {
            if (this.form.id != null) {
                updateProject(this.form).then(response => {
                    this.$modal.msgSuccess('成功')
                    localStorage.setItem('defaultIndex',this.form.defaultIndex)
                })
            }
        },
        getIndexList() {
            listSelectUser().then(response => {
                console.log(response)
                for (let item of response.data) {
                    let obj = {}
                    obj['value'] = item.textValue
                    obj['label'] = item.label
                    this.indexList.push(obj)
                }
            })
        },
    }
}
</script>

<style scoped>

</style>
